﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PropFu;
using System.ComponentModel;

namespace PropFuTest
{

    public class PersonLame : INotifyPropertyChanged
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (value == _name)
                    return;

                _name = value;
                OnPropertyChanged("Name");
            }
        }

        private int _age;
        public int Age
        {
            get { return _age; }
            set
            {
                if (value == _age)
                    return;

                _age = value;
                OnPropertyChanged("Age");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    [NotifyPropertyChanged]
    public class PersonAwesome : INotifyPropertyChanged
    {
        public string Name { get; set; }

        public int Age { get; set; }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        [OnPropertyChanged]
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }



    //This is to illustrate how the properties work, not as a best practice.
    //  It's usually easiest to just have a base class like NotifyingBase that has all your
    //  property changed code in it.
    [NotifyPropertyChanged]
    public class Person : INotifyPropertyChanged
    {
        public string Name { get; set; }

        private int _age;
        public int Age
        {
            get { return _age; }
            set
            {
                //there is a guard clause injected here!
                //if(Age == value)
                //    return;
                _age = value;

                //OnPropertyChanged("Age") is called here!
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        [OnPropertyChanged]
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
